using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using Triton.Common;

namespace Triton.Game
{
	public static class Input
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class Class240
		{
			public static readonly Class240 Instance9 = new Class240();

			internal void method_0(Hotkey hotkey_0)
			{
				DebugMouseCursorPos = !DebugMouseCursorPos;
			}

			internal void method_1(Hotkey hotkey_0)
			{
				ProcessHookManager.Disable();
			}

			internal void method_2(Hotkey hotkey_0)
			{
				ProcessHookManager.Enable();
			}

			internal void method_3(Hotkey hotkey_0)
			{
				ProcessHookManager.Reset();
			}
		}

		[CompilerGenerated]
		private static bool bool_0;

		private static readonly Stopwatch stopwatch_0;

		public static int InputEventMsDelay;

		public static bool DebugMouseCursorPos
		{
			[CompilerGenerated]
			get
			{
				return bool_0;
			}
			[CompilerGenerated]
			set
			{
				bool_0 = value;
			}
		}

		private static IntPtr IntPtr_0 => TritonHs.ClientWindowHandle;

		static Input()
		{
			stopwatch_0 = Stopwatch.StartNew();
			InputEventMsDelay = 5;
			DebugMouseCursorPos = false;
			Hotkeys.Register("TritonHs.Input.DebugMouseCursorPos", Keys.X, ModifierKeys.Alt | ModifierKeys.Shift, delegate
			{
				DebugMouseCursorPos = !DebugMouseCursorPos;
			});
			Hotkeys.Register("TritonHs.ProcessHookManager.Disable", Keys.D, ModifierKeys.Alt | ModifierKeys.Shift, delegate
			{
				ProcessHookManager.Disable();
			});
			Hotkeys.Register("TritonHs.ProcessHookManager.Enable", Keys.E, ModifierKeys.Alt | ModifierKeys.Shift, delegate
			{
				ProcessHookManager.Enable();
			});
			Hotkeys.Register("TritonHs.ProcessHookManager.Reset", Keys.R, ModifierKeys.Alt | ModifierKeys.Shift, delegate
			{
				ProcessHookManager.Reset();
			});
		}

		public static void SetMousePos(int cx, int cy)
		{
			RectWin32 client = ProcessHookManager.WindowInfo.Client;
			ProcessHookManager.ScreenToClient(cx, cy);
			ProcessHookManager.SetCursorPos(cx + client.Left, cy + client.Top);
			MoveMouse(cx, cy);
			if (DebugMouseCursorPos)
			{
				Interop.SetCursorPos(cx + client.Left, cy + client.Top);
			}
		}

		public static void MoveMouse(int cx, int cy)
		{
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				Interop.SendMessage(IntPtr_0, 32, IntPtr_0, (IntPtr)33554433);
				Interop.SendMessage(IntPtr_0, 512, IntPtr.Zero, (IntPtr)((cx & 0xFFFF) | ((cy & 0xFFFF) << 16)));
			}
		}

		internal static void smethod_0(IntPtr intptr_0, IntPtr intptr_1)
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 257, intptr_0, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		internal static void smethod_1(IntPtr intptr_0, IntPtr intptr_1, bool bool_1)
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 256, intptr_0, IntPtr.Zero);
				if (!bool_1)
				{
					Interop.SendMessage(IntPtr_0, 258, intptr_1, IntPtr.Zero);
					Interop.SendMessage(IntPtr_0, 257, intptr_0, IntPtr.Zero);
				}
			}
			stopwatch_0.Restart();
		}

		public static void PressKey(Keys key, bool downOnly = true)
		{
			smethod_1((IntPtr)(int)key, (IntPtr)Interop.MapVirtualKeyW(key), downOnly);
		}

		public static void PressKey(Keys key, char keyCode, bool downOnly = true)
		{
			smethod_1((IntPtr)(int)key, (IntPtr)keyCode, downOnly);
		}

		public static void ReleaseKey(Keys key)
		{
			smethod_0((IntPtr)(int)key, (IntPtr)Interop.MapVirtualKeyW(key));
		}

		public static void ReleaseKey(Keys key, char keyCode)
		{
			smethod_0((IntPtr)(int)key, (IntPtr)keyCode);
		}

		public static void PressLMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 513, (IntPtr)1, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void ReleaseLMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 514, (IntPtr)1, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void DblClickLMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 515, (IntPtr)1, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void PressMMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 519, (IntPtr)16, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void ReleaseMMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 520, (IntPtr)16, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void DblClickMMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 521, (IntPtr)16, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void PressRMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 516, (IntPtr)2, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void ReleaseRMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 517, (IntPtr)2, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void DblClickRMB()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 518, (IntPtr)2, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void PressXB1()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 523, (IntPtr)65568, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void ReleaseXB1()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 524, (IntPtr)65568, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void DblClickXB1()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 525, (IntPtr)65568, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void PressXB2()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 523, (IntPtr)131136, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void ReleaseXB2()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 524, (IntPtr)131136, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}

		public static void DblClickXB2()
		{
			int num = (int)(InputEventMsDelay - stopwatch_0.ElapsedMilliseconds);
			using (TritonHs.Memory.ReleaseFrame(reacquireAsHardLock: true))
			{
				if (num > 0)
				{
					Thread.Sleep(num);
				}
				Interop.SendMessage(IntPtr_0, 525, (IntPtr)131136, IntPtr.Zero);
			}
			stopwatch_0.Restart();
		}
	}
}
